﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime;
using System.Xml;
using System.Configuration;

namespace Tickz
{
    /// <summary>
    /// 配置CS整个应用的参数
    /// </summary>
    public class CSConfigParams : ConfigParams
    {
        //得到虚拟路径的跟路径
        private string applicationRootRealPath = Environment.CurrentDirectory;

        public override string ApplicationRootRealPath
        {
            get { return applicationRootRealPath; }
            set { applicationRootRealPath = value; }
        }

       

        //根据key取得配置的值
        public override string GetTickzConfig(string key)
        {
            XmlDocument document = new XmlDocument();
            document.Load(ApplicationRootRealPath + "\\tickz.Config");
            XmlElement xmlEle = document.GetElementById(key);
            //判断是否存在该节点
            if (xmlEle == null)
            {
                return null;
            }
            return document.GetElementById(key).Attributes["value"].Value;           
        }

        //设置存在的key的值
        public override void SetTickzConfig(string key, string value)
        {
            XmlDocument document = new XmlDocument();
            document.Load(ApplicationRootRealPath + "\\tickz.Config");
            XmlElement xmlEle = document.GetElementById(key);
            //判断是否存在该节点
            if (xmlEle != null)
            {
                document.GetElementById(key).Attributes["value"].Value = value;
                document.Save(ApplicationRootRealPath + "\\tickz.Config");
            }
        }

    }
}

